package com.learnyou.server.xingzuo.biz.client;

import com.learnyou.server.xingzuo.dto.paramDTO.wechat.*;
import com.learnyou.server.xingzuo.dto.paramDTO.wechat.third.*;
import com.learnyou.server.xingzuo.dto.resultDTO.wechat.WechatNormalResultDTO;
import com.learnyou.server.xingzuo.dto.resultDTO.wechat.WechatWxaUrlLinkGenResultDTO;
import com.learnyou.server.xingzuo.dto.wechat.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@FeignClient(name = "wechat-client", url = "https://api.weixin.qq.com")
public interface WechatClient {

    @GetMapping(value = "/sns/jscode2session?appid={appId}&secret={secretKey}&grant_type=authorization_code&js_code={code}", consumes = MediaType.APPLICATION_JSON_VALUE)
    WechatLoginResultDataDTO login(@PathVariable String appId, @PathVariable String secretKey, @PathVariable String code);

    @GetMapping("/cgi-bin/token?grant_type=client_credential&appid={appId}&secret={secretKey}")
    WechatTokenDataDTO token(@PathVariable String appId, @PathVariable String secretKey);

    @PostMapping("/wxa/business/getuserphonenumber?access_token={token}")
    WechatPhoneInfoDTO phoneNumber(@PathVariable String token, @RequestBody WechatPhoneRequestBody phoneBody);

    /**
     * 下发统一模板消息
     * @param token
     * @param templateDTO
     * @return
     */
    @PostMapping("/cgi-bin/message/wxopen/template/uniform_send?access_token={token}")
    WechatNormalResultDTO sendUniformMessage(@PathVariable String token, @RequestBody WechatUniformTemplateMsgDTO templateDTO);

    /**
     * 下发公众号模板消息
     * @param token
     * @param templateMsgParamDTO
     * @return
     */
    @PostMapping("/cgi-bin/message/template/send?access_token={token}")
    WechatNormalResultDTO sendTemplateMessage(@PathVariable String token, @RequestBody WechatNormalTemplateMsgParamDTO templateMsgParamDTO);

    /**
     * 第三方平台token
     * @param paramDTO
     * @return
     */
    @PostMapping("/cgi-bin/component/api_component_token")
    WechatThirdTokenDataDTO thirdToken(@RequestBody WechatThirdTokenParamDTO paramDTO);

    /**
     * 第三方平台预授权码
     * @param thirdToken
     * @param preAuthParamDTO
     * @return
     */
    @PostMapping("/cgi-bin/component/api_create_preauthcode?component_access_token={thirdToken}")
    WechatThirdPreAuthCodeResultDTO getPreAuthCode(@PathVariable String thirdToken, @RequestBody WechatThirdPreAuthParamDTO preAuthParamDTO);

    /**
     * 使用授权码获取授权信息
     * https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/authorization_info.html
     * @return
     */
    @PostMapping("/cgi-bin/component/api_query_auth?component_access_token={thirdToken}")
    WechatThirdAuthResultDTO getApiQueryAuth(@PathVariable String thirdToken, @RequestBody WechatThirdApiQueryAuthParamDTO apiQueryAuthParamDTO);

    /**
     * 获取授权帐号详情
     * @param thirdToken
     * @param thirdAuthorizerInfoQueryParamDTO
     */
    @PostMapping("/cgi-bin/component/api_get_authorizer_info?access_token={thirdToken}")
    WechatThirdAuthorizerResultDTO getAuthorizerInfo(@PathVariable String thirdToken, @RequestBody WechatThirdAuthorizerInfoQueryParamDTO thirdAuthorizerInfoQueryParamDTO);

    /**
     * 获取授权帐号调用令牌
     * https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/ticket-token/getAuthorizerAccessToken.html
     * @return
     */
    @PostMapping("/cgi-bin/component/api_authorizer_token?component_access_token={thirdToken}")
    WechatThirdAuthorizerTokenResultDTO getAuthorizerAccessToken(@PathVariable String thirdToken, @RequestBody WechatThirdAuthorizerTokenParamDTO paramDTO);


    /**
     * 代公众号发起网页授权<br>
     * 通过code换取access_token
     * @param thirdPrivateAuthTokenParamDTO
     * @return
     */
    @GetMapping("/sns/oauth2/component/access_token")
    WechatThirdPrivateAuthTokenResultDTO getThirdPrivateAuthToken(@SpringQueryMap WechatThirdPrivateAuthTokenParamDTO thirdPrivateAuthTokenParamDTO);

    /**
     * 生成小程序链接
     * @param token
     * @param paramDTO
     * @return
     */
    @PostMapping("/wxa/generate_urllink?access_token={token}")
    WechatWxaUrlLinkGenResultDTO generateWxaUrlLink(@PathVariable String token, @RequestBody WechatWxaUrlLinkGenParamDTO paramDTO);

    /**
     * 获得公众号行业信息
     * @param token
     * @return
     */
    @PostMapping("/cgi-bin/template/get_industry?access_token={token}")
    WechatIndustryResultDTO getIndustry(@PathVariable String token);

    /**
     * 添加并获得消息模板ID
     * @param token
     * @return
     */
    @PostMapping("/cgi-bin/template/api_add_template?access_token={token}")
    WechatAddTemplateResultDTO addAndGetTemplateId(@PathVariable String token);

    /**
     * 删除消息模板
     * @param token
     * @return
     */
    @PostMapping("/cgi-bin/template/del_private_template?access_token={token}")
    WechatNormalResultDTO removePrivateTemplate(@PathVariable String token, @RequestBody WechatRemoveTemplateParamDTO paramDTO);

    @GetMapping("/cgi-bin/template/get_all_private_template?access_token={token}")
    WechatTemplateResultDTO getAllPrivateTemplate(@PathVariable String token);

    /**
     * 文本安全识别
     * @param token
     * @return
     */
    @PostMapping("/wxa/msg_sec_check?access_token={token}")
    WechatContentSecurityCheckResultDTO msgSecurityCheck(@PathVariable String token, @RequestBody WechatTextSecurityCheckParamDTO checkParamDTO);

    /**
     * 音视频内容安全识别(异步)
     * @param token
     * @return
     */
    @PostMapping("/wxa/media_check_async?access_token={token}")
    WechatContentSecurityCheckResultDTO mediaSecurityCheck(@PathVariable String token, @RequestBody WechatMediaSecurityCheckParamDTO checkParamDTO);
}
